package com.macro.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.macro.mall.dto.e.SysWebEntDTO;
import com.macro.mall.dto.o.SysWebOutDTO;
import com.macro.mall.mapper.BasicPlatformMapper;
import com.macro.mall.model.BasicPlatform;
import com.macro.mall.service.SysWebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SysWebServiceImpl implements SysWebService {

    @Autowired
    private BasicPlatformMapper basicPlatformMapper;

    @Override
    public PageInfo<SysWebOutDTO> list(SysWebEntDTO sysWebEntDTO) {
        PageHelper.startPage(sysWebEntDTO.getPage(),sysWebEntDTO.getPageSize());
        List<BasicPlatform> list = basicPlatformMapper.list(sysWebEntDTO.getWebName());
        PageInfo<BasicPlatform> basicPlatformPageInfo = new PageInfo<>(list);
        List<SysWebOutDTO> list1=new ArrayList();
        for (BasicPlatform basicPlatform:list){
            SysWebOutDTO sysWebOutDTO = new SysWebOutDTO();
            sysWebOutDTO.setId(basicPlatform.getId());
            sysWebOutDTO.setName(basicPlatform.getName());
            sysWebOutDTO.setCreatedDt(basicPlatform.getCreatedDt());
            sysWebOutDTO.setStatus(basicPlatform.getStatus());
            list1.add(sysWebOutDTO);
        }
        PageInfo<SysWebOutDTO> sysWebOutDTOPageInfo = new PageInfo<>(list1);
        sysWebOutDTOPageInfo.setTotal(basicPlatformPageInfo.getTotal());
        return sysWebOutDTOPageInfo;
    }

    @Override
    public int modify(SysWebEntDTO sysWebEntDTO) {
        BasicPlatform basicPlatform = new BasicPlatform();
        basicPlatform.setId(sysWebEntDTO.getId());
        basicPlatform.setStatus(sysWebEntDTO.getStatus());
        basicPlatform.setName(sysWebEntDTO.getWebName());
//        basicPlatform.setDomain(sysWebEntDTO.get);
        int i = basicPlatformMapper.updateByPrimaryKeySelective(basicPlatform);
        return i;
    }
}
